<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%response.setHeader("cache-control","public"); %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<!-- 创建试卷第二步 -->
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<title>在线考试系统</title>
<link rel="stylesheet" type="text/css"
	href="<%=path %>/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/css/common.css">
<link rel="stylesheet" type="text/css"
	href="<%=path %>/css/examMng/paperMng.css">
<style type="text/css">
.deletebox2 {
	margin-left: 6px;
	line-height: 60px
}

.qutype {
	height: 60px;
	border: 1px solid #ccc;
	width: 90%;
	border-top-right-radius: 4px;
	border-bottom-right-radius: 4px;
	padding-left: 10px;
}

.qutypeCode {
	height: 60px;
	border: 1px solid #ccc;
	width: 90%;
	border-left: none;
	border-top-right-radius: 4px;
	border-bottom-right-radius: 4px;
	padding-left: 10px;
}
</style>
<script src="<%=path%>/static/js/respond.js"></script>


	<!--[if !IE]> -->
	<script type="text/javascript">
		window.jQuery || document.write("<script src='<%=path%>/static/js/jquery-2.0.3.min.js'>" + "<" + "/script>");
	</script>
	<!-- <![endif]-->

	<script type="text/javascript">
		window.jQuery || document.write("<script src='<%=path%>/static/js/jquery-1.9.1.min.js'>" + "<" + "/script>");
	</script>
	<script type="text/javascript" src="<%=path%>/static/js/bootstrap.min.js"></script>
	<script src="<%=path%>/static/js/jquery.selectlist.js"></script>
	<script>
		$(function () {
			$("[data-toggle='tooltip']").tooltip();
		});
	</script>
</head>
<body>

	<jsp:include page="../head.jsp" flush="true" />

	<!--body begin-->
	<div class="main-container">
		<div class="container body-box">
			<div class="title-top">
				<p>试题类型维护:</p>
				<a href="javascript:history.go(-1);" class="retun"><i
					class="glyphicon glyphicon-arrow-left"></i>返回</a>
			</div>
			<div class="paper-content">
				<div class="outcontent">
					<!--试卷配置信息 begin-->
					<div class="deploy-main">
						<div class="deploy-top">
							<a id="addexam" class="btn btn-default add-exam"><i
								class="glyphicon glyphicon-plus-sign"></i>添加试题类型</a>
							<!--<a class="btn btn-default loading">载入模板</a>-->
						</div>
						<div id="deployadd" class="deploy-content">
							<c:forEach items="${qutypeList }" var="qutype">
								<div class="deploybox row">
									<div class="col-lg-11 col-md-11 line-right">
										<div class="input-group input-group-lg deploytype">
											<input name="qutypeId" type="hidden" value="${qutype.id }">
											<span class="input-group-addon">题目类型</span> <input
												name="qutype" type="text" class="qutype"
												placeholder="请输入题目类型" value="${qutype.name }"> <span
												class="input-group-addon">类型代码</span> <input
												name="qutypeCode" type="text" class="qutypeCode"
												placeholder="请输入题目类型代码" value="${qutype.code }" />
										</div>
									</div>
									<div class="col-lg-1 col-md-1">
										<div class="deletebox2">
											<i class="glyphicon glyphicon-trash"></i> <a
												onclick="delType(${qutype.id })">删除</a>
										</div>
									</div>
								</div>
							</c:forEach>

						</div>
					</div>
					<!--试卷配置信息 end-->
					<div class="btnbox" style="width: 207px;">
						<a class="btn btn-success" onclick="save();">保存</a>

					</div>
				</div>
			</div>
		</div>
	</div>
	<!--body end-->

	<script type="text/javascript">

	$(function(){
		// $('#topMain').children().eq(3).addClass('active'); // 追加样式;
		// $('#topMain').children().eq(3).children().attr('href','#');

		//大类管理
		if (${role eq 'master'}) {
			$('#topMain').children().eq(0).addClass('active'); // 追加样式;
			$('#topMain').children().eq(0).children().attr('href', '#');
		} else if (${role eq 'trainee'}) {
			$('#topMain').children().eq(0).addClass('active'); // 追加样式;
			$('#topMain').children().eq(0).children().attr('href', '#');
		} else {
			$('#topMain').children().eq(3).addClass('active'); // 追加样式;
			// $('#topMain').children().eq(3).children().attr('href', '#');
		}

	})
			//paper-add-deploy.htm添加试题类型按钮
			$(document).ready(function() {
				var nums = $(".knowsmain li").length;
				for (var i = 0 ; i< nums;i++) {
					$(".knowsmain").children().eq(i).find(".twobox").find("input").val(0);
				}
				$('#addexam').click(function() {
					var tipcon =
						'<div class="deploybox row">'+
					    '<div class="col-lg-11 col-md-11 line-right">'+
						'<div class="input-group input-group-lg deploytype">'+
						'<span class="input-group-addon">题目类型</span>'+
						'<input name="qutypeId" type="hidden" value="">'+
						'<input name="qutype" type="text" class="qutype" maxlength="20" placeholder="请输入题目类型"/>'+
						'<span class="input-group-addon">类型代码</span>'+
						'<input name="qutypeCode" type="text" class="qutypeCode" maxlength="10" placeholder="请输入题目类型代码"/>'+
						'</div>'+
						'</div>'+
						'<div class="col-lg-1 col-md-1">'+
						'<div class="deletebox2" >'+
						'<i class="glyphicon glyphicon-trash"></i>'+
						'<a >删除</a>'+
						'</div>'+
						'</div>'+
						'</div>'
					$('#deployadd').append(tipcon);
					// 删除表单
					$('.deletebox2 a').click(function() {
						$(this).parent().parent().parent().remove();
						});
			
				});
				

			});
			function delType(delId){
				if(delId){
					$.ajax({
						type:"POST",
						url:"<%=basePath%>questionType/deltype",
						data:{"delId":delId},
						success:function(data){
							if(data.status==1){
								alert(data.msg);
								$(this).parent().parent().parent().remove();
								window.location.reload();
							}
							
						}
					})
				}else{
					$(this).parent().parent().parent().remove();
				}
			}

			//文本框默认提示文字
			function textFocus(el) {
			    if (el.defaultValue == el.value) { el.value = ''; el.style.color = '#333'; }
			}
			
			//保存
			function save(){
				var typeArr = [];
				
				var typename =[];
				var typecode =[];
				
				$("#deployadd .input-group").each(function () {
					var qutypeId = $($(this).children().get(0)).val();
				    var qutype = $($(this).children().get(2)).val();
				    var qutypeCode = $($(this).children().get(4)).val();
				    qutype = qutype.replace(/(^\s*)|(\s*$)/g, "");
				    qutypeCode = qutypeCode.replace(/(^\s*)|(\s*$)/g, "");
				    var type = new Object();
				    type.id = qutypeId;
				    type.name = qutype;
				    type.code = qutypeCode
				    typeArr.push(type);
				    
				   typename.push(qutype)
				   typecode.push(qutypeCode)
				   
				})
				//console.info(JSON.stringify(typeArr));
				var typex = typename.indexOf("")
				var typecodex = typecode.indexOf("")
				
		if(typex==-1&&typecodex==-1){
			var ary = typecode.sort();
			for (var i = 0; i < typecode.length; i++) {
				if(ary[i]==ary[i+1]){
					alert(ary[i]+"输入重复")
					return
				}
			}
				$.ajax({
					
					type:"POST",
					url:"<%=basePath%>questionType/save",
					data:{"typeList":JSON.stringify(typeArr)},
					success:function(data){
						alert(data.msg);
					}
				})

		}else{
			if(typex!=-1){
				alert("题目类型输入不能为空")
			}
			if(typecodex!=-1){
				alert("代码类型输入不能为空")
			}
			}
				
		}
		</script>

</body>
</html>
